package thread;

public class M1132 {
    public static void main(String[] args){
        new NewThread1132();

        try {
            for(int i=5;i>0;i--){
                System.out.println("Main Thread: "+i);
                Thread.sleep(1000);
            }
        }catch (InterruptedException e){
            System.out.println("Main thread interrupted.");
        }
        System.out.println("Main thread exiting.");
    }
}

//Create a second thread by extending Thread
class NewThread1132 extends Thread{

    NewThread1132(){
        //Create a new,second thread

        super("Demo Thread");
        System.out.println("Child thread: "+this);
        start();
    }

    //This is the entry point for the second thread.


    @Override
    public void run() {
        try {
            for(int i=5;i>0;i--){
                System.out.println("Child Thread: "+i);
                Thread.sleep(500);
            }
        }catch (InterruptedException e){
            System.out.println("Child interrupted.");
        }
        System.out.println("Exiting child thread.");
    }
}
